package org.budo.validation.exception;

import javax.validation.constraints.Pattern;

/**
 * @author lmw
 */
public class BudoPatternValidationException extends AbstractBudoValidationException {
    private static final long serialVersionUID = -8140734408932077617L;

    private static final String MESSAGE_DEFAULT = "{javax.validation.constraints.Pattern.message}";

    public BudoPatternValidationException(Integer parameterIndex, String parameterName, Pattern annotation, CharSequence parameterValue) {
        super(parameterIndex, parameterName, annotation, parameterValue, validationMessage(annotation.message(), MESSAGE_DEFAULT));
    }

    @Override
    protected String buildMessage() {
        Pattern pattern = (Pattern) this.getAnnotation();
        return "parameter[" + this.getParameterIndex() + "] " + this.getParameterName() + " not match " + pattern.regexp();
    }
}